module WsClient
	module Ietf00
	
		module Framing
			def create_frame(message, options = {})
				WsClient::Ietf00::Frame.new(message)
			end
			
			def read_frame
				byte = socket.recv(1)
				
				case byte
					when "\x00" then
						message = []
						while (byte = socket.recv(1)) != "\xFF" do
							message << byte
						end
						
						message = message.join('').utf8
						create_frame(message)
					when "\xFF" then
						throw :closing
					else
						raise WsClient::WebSocketError.new("Unknown header byte '#{byte}'")
						#raise WsClient::FrameError.new("Unknown header byte '#{byte}'")
				end
			end
		end
	
	end
end
